<?php defined('SYSPATH') or die('No direct access allowed.');

	class Jqgrid_Core{
		
		private $model;
		
		public function __construct($entity_name,$grid_listener){
			$this->model = $this->createModel($entity_name, $grid_listener);
		}
		
		public function getList($criteria){
			$req = $this->createRequest($criteria);
			return $this->model->getModelData($req,$criteria);
		}
		
		public function save($oper, $data){
			$id = ($oper == "add")? 0: $data['id'];
			if ($oper == "del") return $this->model->delete($id);
			return $this->model->save($id, $data);
		}
			
		//Seria el equivalente del load => simplemente muestra una grilla por pantalla
		public function render($grid_conf, $grid_parameters = false, $scripts = false){
			$view = new View_Jqgrid($grid_conf, $grid_parameters, $scripts);
			return $view->render($this->model->entity_name);
		}
		
		
		//Metodo de creacion del modelo
		private function createModel($entity_name, $grid_listener){
			return new Jqgrid_Gridmodel($entity_name, $grid_listener);
		}
		
		//Metodo de creacion de la peticion
		private function createRequest($criteria){
			return new Jqgrid_Gridrequest($criteria);
		}
		
	}
?>
 

